class Base{
    isEmpty(param){
        //1.判断param是对象还是数组
        //2中方法  Array.isArray()   instanceof
        if(Array.isArray(param)){
            return param.length ? param.length : '数组为空';
        }else{
            return Object.keys(param).length ? Object.keys(param).length : '对象为空';
        }
    }
}

const fs = require('fs');

const path = require('path');

class Util extends Base{
    constructor(option){
        super(option)
    }

    loadJs(path){
        return this.readFile(path);
    }

    loadCss(path){
        return this.readFile(path);
    }

    loadImg(path){
        return this.readFile(path,'base64');
    }

    readFile(path,type){
        return new Promise((resolve,reject) => {
            fs.readFile(path,type,(error,data) =>{
                if(error){
                    reject(error);
                }else{
                    resolve(data);
                }
            })
        })
    }

    async init(arr){
        let res = [];
        for(let i = 0;i<arr.length;i++){
            //分情况读取文件
            let extname = path.extname(arr[i]).slice(1);
            extname = /^(jpg|png)$/.test(extname) ? 'img' : extname;
            let type = extname[0].toUpperCase() + extname.slice(1);
            type = `load${type}`;
            let data = await this[type](arr[i]);
            res.push(data);
        }
        return res;
    }
}

let util = new Util();

console.log(util.isEmpty([1]));

console.log(util.isEmpty({name:'lili'}));

util.init(['./src/index.js','./src/index.css','./src/1.jpg']).then(res => {
    console.log(res);
})

//作业：1.案例  promise  使用  封装  2.找两个面试题，文字描述形式  算法题

//栈和队列